# Data preparation file - Conflict and salience as drivers of corporate lobbying? #

#Loading packages
library(tidyverse)
library(broom)
library(psych)
library(ggpubr)
library(WebPower)

#Loading data
data <- read.csv("nl_se.csv", sep = ";")
dataI<- read.csv("de_se.csv", sep = ";")

#Appending German observations to Dutch observations for DV
test1 <- data %>% dplyr::select(.,Q40_1, Q40_2)
test2 <- dataI %>% dplyr::select(.,Q40_1, Q40_2)

# Creating condition variable
data <- data %>% as_tibble(.) %>% 
  mutate(conditions = 
           dplyr::case_when(
             Q104==4 ~ 1,
             Q106==4 ~ 2,
             Q108==4 ~ 3,
             Q110==4 ~ 4, 
           ))

dataI <- dataI %>% as_tibble(.) %>% 
  mutate(conditionsI = 
           dplyr::case_when(
             Q104==4 ~ 1,
             Q106==4 ~ 2,
             Q108==4 ~ 3,
             Q110==4 ~ 4, 
           ))

#Prepping condition variables and dataset
test3 <- data %>% dplyr::select(.,conditions)
test4 <- dataI %>% dplyr::select(.,conditionsI)
names(test4) <- "conditions"

merged_data_test <- bind_rows(test1, test2)
conditions_final <- bind_rows(test3,test4)
merged_data_test <- merged_data_test %>% as_tibble(.)
conditions_final <- conditions_final %>% as_tibble(.)

merged_data_test <- merged_data_test %>% as_tibble(.) %>% mutate(conditions_final$conditions)
names(conditions_final) <- "conditions"
subset_foranalysis <- merged_data_test %>% dplyr::slice(.,2:258)
subset_foranalysis <- subset_foranalysis %>% rename(vignettes = `conditions_final$conditions`)
subset_foranalysis <- subset_foranalysis %>% na_if("")

View(subset_foranalysis)

# Creating variables salience and conflict

subset_foranalysis <- subset_foranalysis %>% as_tibble(.) %>%
  mutate(conflictvariable =
           dplyr::case_when(
             vignettes==3 ~ 0,
             vignettes==4 ~ 0,
             vignettes==1 ~ 1,
             vignettes==2 ~ 1,
           ))

subset_foranalysis <- subset_foranalysis %>% as_tibble(.) %>%
  mutate(saliencevariable =
           dplyr::case_when(
             vignettes==1 ~ 0,
             vignettes==3 ~ 0,
             vignettes==2 ~ 1,
             vignettes==4 ~ 1
           ))

write.csv(subset_foranalysis, 'subset_analyse442020.csv')
